# -*- coding: utf-8 -*-
"""
-------------------------------------------------
Project Name: luffcity study project
File Name: 读取ini文件.py
Author: kij
Create Date: 2021/2/8
-------------------------------------------------
"""
import os
import configparser


def get_file_path(file_name):
	return os.path.join(os.path.dirname(os.path.abspath(__file__)), "files", file_name)


file_path = get_file_path("my.ini")
config = configparser.ConfigParser()
config.read(file_path, encoding='utf-8')
# 获取到全部节点
result = config.sections()
# 输出节点列表
print(result)
# 根据节点名称得到内部的元组列表
print(config.items('mysqld_safe'))
# 循环输出对应的元组
for key, value in config.items('mysqld_safe'):
	print(key,value)
print(config.get('mysqld','collation-server'))
# 判断是否存在
v1 = config.has_section('client')
print(v1)
# if not config.has_section('group'):
# 	config.add_section('group')
# 	# 添加键值和内容
# 	config.set('group','天啊','什么万一')
# 	config.write(open(file_path,mode='w',encoding='utf-8'))
# v2 = config.has_section('group')
# print(v2)
config.remove_section('group')
config.remove_option('group','pid-file')
v3 = config.has_section('group')
config.write(open(file_path,mode='w',encoding='utf-8'))
print(v3)